package 美团笔试;

import java.util.Arrays;
import java.util.Scanner;

/**
 @author fujiangnan
 @create 2021-09-25-15-50
 @desc ...
 */
public class Main2 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int len = sc.nextInt();
        int[] arr = new int[len];
        int k = sc.nextInt();
        for (int i = 0; i < len; i++) {
            arr[i] = sc.nextInt();
        }
        int ans = method(arr, k);
        System.out.println(ans);
        System.out.println(0);
    }

    public static int method(int[] arr, int k) {
        int[][] dp = new int[arr.length + 1][k + 1];
        if (k >= arr.length) {
            return 0;
        }
        Arrays.sort(arr);
        for (int i = 0; i <= k; i++) {
            dp[1][i] = 0;
        }
        for (int i = 1; i <= arr.length; i++) {
            dp[i][1] = arr[i-1] - arr[0];
        }
        for (int i = 1; i <= arr.length; i++) {
            for (int j = 1; j <= k; j++) {
                dp[i][j] = Math.min(dp[i-1][j-1], arr[arr.length-1]-arr[i-1]);
            }
        }
        return dp[arr.length][k];
    }

}
